package com.example.covid.service;

import com.example.covid.Utils.Result;
import com.example.covid.dao.UserMapper;
import com.example.covid.pojo.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author KamenRider
 */
@Service("UserService")
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    /**
     * 登录
     * @param user
     * @return
     */
    @Override
    public User login(User user) {
        User login = userMapper.userLogin(user);
        if (user != null) {
            BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
            // 参数1是请求密码， 参数2是数据库中加密的值
            boolean matches = passwordEncoder.matches(user.getUserPassWord(), login.getUserPassWord());
            if (matches) {
                return login;
            }
        }
        //登陆失败
        return null;
    }
}
